<%@ page import="com.situ.web.util.PageInfo" %>
<%@ page import="com.situ.web.pojo.User" %><%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2023/7/28
  Time: 9:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="static/bootstrap-3.4.1-dist/css/bootstrap.css">
</head>
<body>
    <a class="btn btn-primary" href="${pageContext.request.contextPath}/user_add.jsp">添加</a>
    <table class="table table-striped table-bordered table-hover table-condensed">
        <tr>
            <td>ID</td>
            <td>名字</td>
            <td>密码</td>
            <td>年龄</td>
            <td>性别</td>
            <td>编辑</td>
            <td>删除</td>
        </tr>
        <c:forEach items="${pageInfo.list}" var="user">
            <tr>
                <td>${user.id}</td>
                <td>${user.name}</td>
                <td>${user.password}</td>
                <td>${user.age}</td>
                <td>${user.gender}</td>
                <td><a href="${pageContext.request.contextPath}/user?method=getUserUpdatePage&id=${user.id}">编辑</a></td>
                <td><a href="javascript:deleteById(${user.id})">删除</a></td>
            </tr>
        </c:forEach>
    </table>

    <nav aria-label="Page navigation">
        <ul class="pagination">
            <c:if test="${pageInfo.pageNo==1}">
                <li class="disabled">
                    <a href="#" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pageInfo.pageNo!=1}">
                <li>
                    <a href="${pageContext.request.contextPath}/user?method=selectByPage&pageNo=${pageInfo.pageNo-1}" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>

            <c:forEach begin="1" end="${pageInfo.totalPage}" var="i">
                <c:if test="${i==pageInfo.pageNo}">
                    <li class="active"><a href="#">${i}</a></li>
                </c:if>
                <c:if test="${i!=pageInfo.pageNo}">
                    <li><a href="${pageContext.request.contextPath}/user?method=selectByPage&pageNo=${i}">${i}</a></li>
                </c:if>
            </c:forEach>

            <li>
                <a href="${pageContext.request.contextPath}/user?method=selectByPage&pageNo=${pageInfo.pageNo+1}" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>
        </ul>
    </nav>

    <script>
        function deleteById(id) {
            var isDelete = confirm('您确认要删除？');
            if (isDelete) {
                location.href = '${pageContext.request.contextPath}/user?method=deleteById&id=' + id;
            }
        }
    </script>
</body>
</html>
